<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP, NoImplicitPrelude #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Module      :  GHC.IO.Handle.FD</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow, 1994-2008</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- </span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability :  non-portable</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Handle operations implemented by file descriptors (FDs)</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.IO.Handle.FD</span><span> </span><span class="hs-special">(</span><span> </span><span>
</span><span id="line-19"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.FD.html#stdin"><span class="hs-identifier">stdin</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#stdout"><span class="hs-identifier">stdout</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#stderr"><span class="hs-identifier">stderr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-20"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.FD.html#openFile"><span class="hs-identifier">openFile</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#openBinaryFile"><span class="hs-identifier">openBinaryFile</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#openFileBlocking"><span class="hs-identifier">openFileBlocking</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.FD.html#mkHandleFromFD"><span class="hs-identifier">mkHandleFromFD</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#fdToHandle"><span class="hs-identifier">fdToHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#fdToHandle%27"><span class="hs-identifier">fdToHandle'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#handleToFd"><span class="hs-identifier">handleToFd</span></a></span><span>
</span><span id="line-22"></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Maybe.html"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Typeable.html"><span class="hs-identifier">Data.Typeable</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.Types.html"><span class="hs-identifier">Foreign.C.Types</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.MVar.html"><span class="hs-identifier">GHC.MVar</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html"><span class="hs-identifier">GHC.IO.Encoding</span></a></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Device.html"><span class="hs-identifier">GHC.IO.Device</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">IODevice</span></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html"><span class="hs-identifier">GHC.IO.IOMode</span></a></span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html"><span class="hs-identifier">GHC.IO.Handle.Types</span></a></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html"><span class="hs-identifier">GHC.IO.Handle.Internals</span></a></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.IO.FD.html"><span class="hs-identifier">GHC.IO.FD</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">FD</span></span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="System.Posix.Internals.html"><span class="hs-identifier">System.Posix.Internals</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Posix</span></span><span>
</span><span id="line-39"></span><span>
</span><span id="line-40"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-41"></span><span class="hs-comment">-- Standard Handles</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-comment">-- Three handles are allocated during program initialisation.  The first</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- two manage input or output from the Haskell program's standard input</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- or output channel respectively.  The third manages output to the</span><span>
</span><span id="line-46"></span><span class="hs-comment">-- standard error channel. These handles are initially open.</span><span>
</span><span id="line-47"></span><span>
</span><span id="line-48"></span><span class="hs-comment">-- | A handle managing input from the Haskell program's standard input channel.</span><span>
</span><span id="line-49"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#stdin"><span class="hs-identifier hs-type">stdin</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-50"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#stdin"><span class="hs-pragma hs-type">stdin</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-51"></span><span id="stdin"><span class="annot"><span class="annottext">stdin :: Handle
</span><a href="GHC.IO.Handle.FD.html#stdin"><span class="hs-identifier hs-var hs-var">stdin</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO Handle -&gt; Handle
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Handle -&gt; Handle) -&gt; IO Handle -&gt; Handle
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-52"></span><span>   </span><span class="hs-comment">-- ToDo: acquire lock</span><span>
</span><span id="line-53"></span><span>   </span><span class="annot"><span class="annottext">FD -&gt; IO ()
</span><a href="GHC.IO.Handle.FD.html#setBinaryMode"><span class="hs-identifier hs-var">setBinaryMode</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="GHC.IO.FD.html#stdin"><span class="hs-identifier hs-var">FD.stdin</span></a></span><span>
</span><span id="line-54"></span><span>   </span><span id="local-6989586621679554657"><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679554657"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getLocaleEncoding"><span class="hs-identifier hs-var">getLocaleEncoding</span></a></span><span>
</span><span id="line-55"></span><span>   </span><span class="annot"><span class="annottext">FD
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkHandle"><span class="hs-identifier hs-var">mkHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="GHC.IO.FD.html#stdin"><span class="hs-identifier hs-var">FD.stdin</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&lt;stdin&gt;&quot;</span></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ReadHandle"><span class="hs-identifier hs-var">ReadHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextEncoding -&gt; Maybe TextEncoding
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679554657"><span class="hs-identifier hs-var">enc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-56"></span><span>                </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="GHC.IO.Handle.Types.html#nativeNewlineMode"><span class="hs-identifier hs-var">nativeNewlineMode</span></a></span><span class="hs-comment">{-translate newlines-}</span><span>
</span><span id="line-57"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HandleFinalizer -&gt; Maybe HandleFinalizer
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">HandleFinalizer
</span><a href="GHC.IO.Handle.FD.html#stdHandleFinalizer"><span class="hs-identifier hs-var">stdHandleFinalizer</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe (MVar Handle__)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="hs-comment">-- | A handle managing output to the Haskell program's standard output channel.</span><span>
</span><span id="line-60"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#stdout"><span class="hs-identifier hs-type">stdout</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-61"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#stdout"><span class="hs-pragma hs-type">stdout</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-62"></span><span id="stdout"><span class="annot"><span class="annottext">stdout :: Handle
</span><a href="GHC.IO.Handle.FD.html#stdout"><span class="hs-identifier hs-var hs-var">stdout</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO Handle -&gt; Handle
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Handle -&gt; Handle) -&gt; IO Handle -&gt; Handle
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-63"></span><span>   </span><span class="hs-comment">-- ToDo: acquire lock</span><span>
</span><span id="line-64"></span><span>   </span><span class="annot"><span class="annottext">FD -&gt; IO ()
</span><a href="GHC.IO.Handle.FD.html#setBinaryMode"><span class="hs-identifier hs-var">setBinaryMode</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="GHC.IO.FD.html#stdout"><span class="hs-identifier hs-var">FD.stdout</span></a></span><span>
</span><span id="line-65"></span><span>   </span><span id="local-6989586621679554650"><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679554650"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getLocaleEncoding"><span class="hs-identifier hs-var">getLocaleEncoding</span></a></span><span>
</span><span id="line-66"></span><span>   </span><span class="annot"><span class="annottext">FD
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkHandle"><span class="hs-identifier hs-var">mkHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="GHC.IO.FD.html#stdout"><span class="hs-identifier hs-var">FD.stdout</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&lt;stdout&gt;&quot;</span></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#WriteHandle"><span class="hs-identifier hs-var">WriteHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextEncoding -&gt; Maybe TextEncoding
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679554650"><span class="hs-identifier hs-var">enc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-67"></span><span>                </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="GHC.IO.Handle.Types.html#nativeNewlineMode"><span class="hs-identifier hs-var">nativeNewlineMode</span></a></span><span class="hs-comment">{-translate newlines-}</span><span>
</span><span id="line-68"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HandleFinalizer -&gt; Maybe HandleFinalizer
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">HandleFinalizer
</span><a href="GHC.IO.Handle.FD.html#stdHandleFinalizer"><span class="hs-identifier hs-var">stdHandleFinalizer</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe (MVar Handle__)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-69"></span><span>
</span><span id="line-70"></span><span class="hs-comment">-- | A handle managing output to the Haskell program's standard error channel.</span><span>
</span><span id="line-71"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#stderr"><span class="hs-identifier hs-type">stderr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-72"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html#stderr"><span class="hs-pragma hs-type">stderr</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-73"></span><span id="stderr"><span class="annot"><span class="annottext">stderr :: Handle
</span><a href="GHC.IO.Handle.FD.html#stderr"><span class="hs-identifier hs-var hs-var">stderr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO Handle -&gt; Handle
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Handle -&gt; Handle) -&gt; IO Handle -&gt; Handle
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-74"></span><span>    </span><span class="hs-comment">-- ToDo: acquire lock</span><span>
</span><span id="line-75"></span><span>   </span><span class="annot"><span class="annottext">FD -&gt; IO ()
</span><a href="GHC.IO.Handle.FD.html#setBinaryMode"><span class="hs-identifier hs-var">setBinaryMode</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="GHC.IO.FD.html#stderr"><span class="hs-identifier hs-var">FD.stderr</span></a></span><span>
</span><span id="line-76"></span><span>   </span><span id="local-6989586621679554647"><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679554647"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getLocaleEncoding"><span class="hs-identifier hs-var">getLocaleEncoding</span></a></span><span>
</span><span id="line-77"></span><span>   </span><span class="annot"><span class="annottext">FD
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkHandle"><span class="hs-identifier hs-var">mkHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="GHC.IO.FD.html#stderr"><span class="hs-identifier hs-var">FD.stderr</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&lt;stderr&gt;&quot;</span></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#WriteHandle"><span class="hs-identifier hs-var">WriteHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-comment">{-stderr is unbuffered-}</span><span> </span><span>
</span><span id="line-78"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextEncoding -&gt; Maybe TextEncoding
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679554647"><span class="hs-identifier hs-var">enc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-79"></span><span>                </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="GHC.IO.Handle.Types.html#nativeNewlineMode"><span class="hs-identifier hs-var">nativeNewlineMode</span></a></span><span class="hs-comment">{-translate newlines-}</span><span>
</span><span id="line-80"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HandleFinalizer -&gt; Maybe HandleFinalizer
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">HandleFinalizer
</span><a href="GHC.IO.Handle.FD.html#stdHandleFinalizer"><span class="hs-identifier hs-var">stdHandleFinalizer</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe (MVar Handle__)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-81"></span><span>
</span><span id="line-82"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#stdHandleFinalizer"><span class="hs-identifier hs-type">stdHandleFinalizer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-83"></span><span id="stdHandleFinalizer"><span class="annot"><span class="annottext">stdHandleFinalizer :: HandleFinalizer
</span><a href="GHC.IO.Handle.FD.html#stdHandleFinalizer"><span class="hs-identifier hs-var hs-var">stdHandleFinalizer</span></a></span></span><span> </span><span id="local-6989586621679554646"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554646"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span id="local-6989586621679554645"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679554645"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-84"></span><span>  </span><span id="local-6989586621679554644"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679554644"><span class="hs-identifier hs-var">h_</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; IO Handle__
forall a. MVar a -&gt; IO a
</span><a href="GHC.MVar.html#takeMVar"><span class="hs-identifier hs-var">takeMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679554645"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-85"></span><span>  </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushWriteBuffer"><span class="hs-identifier hs-var">flushWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679554644"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-86"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; HandleType
</span><a href="GHC.IO.Handle.Types.html#haType"><span class="hs-identifier hs-var hs-var">haType</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679554644"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span>
</span><span id="line-87"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ClosedHandle"><span class="hs-identifier hs-var">ClosedHandle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-88"></span><span>      </span><span id="local-6989586621679554639"><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679554639"><span class="hs-identifier hs-var">_other</span></a></span></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#closeTextCodecs"><span class="hs-identifier hs-var">closeTextCodecs</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679554644"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-89"></span><span>  </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; Handle__ -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679554645"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; Handle__
</span><a href="GHC.IO.Handle.Internals.html#ioe_finalizedHandle"><span class="hs-identifier hs-var">ioe_finalizedHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554646"><span class="hs-identifier hs-var">fp</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-90"></span><span>
</span><span id="line-91"></span><span class="hs-comment">-- We have to put the FDs into binary mode on Windows to avoid the newline</span><span>
</span><span id="line-92"></span><span class="hs-comment">-- translation that the CRT IO library does.</span><span>
</span><span id="line-93"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#setBinaryMode"><span class="hs-identifier hs-type">setBinaryMode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.FD.html#FD"><span class="hs-identifier hs-type">FD.FD</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span id="setBinaryMode"><span class="annot"><span class="annottext">setBinaryMode :: FD -&gt; IO ()
</span><a href="GHC.IO.Handle.FD.html#setBinaryMode"><span class="hs-identifier hs-var hs-var">setBinaryMode</span></a></span></span><span> </span><span id="local-6989586621679554635"><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554635"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CInt -&gt; Bool -&gt; IO CInt
</span><a href="GHC.IO.Handle.FD.html#setmode"><span class="hs-identifier hs-var">setmode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FD -&gt; CInt
</span><a href="GHC.IO.FD.html#fdFD"><span class="hs-identifier hs-var hs-var">FD.fdFD</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554635"><span class="hs-identifier hs-var">fd</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-96"></span><span>                      </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span class="hs-identifier">setBinaryMode</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;__hscore_setmode&quot;</span></span><span>
</span><span id="line-103"></span><span>  </span><span id="setmode"><span class="annot"><a href="GHC.IO.Handle.FD.html#setmode"><span class="hs-identifier hs-var">setmode</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-106"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-107"></span><span class="hs-comment">-- Opening and Closing Files</span><span>
</span><span id="line-108"></span><span>
</span><span id="line-109"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#addFilePathToIOError"><span class="hs-identifier hs-type">addFilePathToIOError</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#IOException"><span class="hs-identifier hs-type">IOException</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#IOException"><span class="hs-identifier hs-type">IOException</span></a></span><span>
</span><span id="line-110"></span><span id="addFilePathToIOError"><span class="annot"><span class="annottext">addFilePathToIOError :: FilePath -&gt; FilePath -&gt; IOException -&gt; IOException
</span><a href="GHC.IO.Handle.FD.html#addFilePathToIOError"><span class="hs-identifier hs-var hs-var">addFilePathToIOError</span></a></span></span><span> </span><span id="local-6989586621679554631"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554631"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679554630"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554630"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span id="local-6989586621679554629"><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679554629"><span class="hs-identifier hs-var">ioe</span></a></span></span><span>
</span><span id="line-111"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679554629"><span class="hs-identifier hs-var">ioe</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ioe_location :: FilePath
</span><a href="GHC.IO.Exception.html#ioe_location"><span class="hs-identifier hs-var">ioe_location</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554631"><span class="hs-identifier hs-var">fun</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ioe_filename :: Maybe FilePath
</span><a href="GHC.IO.Exception.html#ioe_filename"><span class="hs-identifier hs-var">ioe_filename</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Maybe FilePath
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554630"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-112"></span><span>
</span><span id="line-113"></span><span class="hs-comment">-- | Computation 'openFile' @file mode@ allocates and returns a new, open</span><span>
</span><span id="line-114"></span><span class="hs-comment">-- handle to manage the file @file@.  It manages input if @mode@</span><span>
</span><span id="line-115"></span><span class="hs-comment">-- is 'ReadMode', output if @mode@ is 'WriteMode' or 'AppendMode',</span><span>
</span><span id="line-116"></span><span class="hs-comment">-- and both input and output if mode is 'ReadWriteMode'.</span><span>
</span><span id="line-117"></span><span class="hs-comment">--</span><span>
</span><span id="line-118"></span><span class="hs-comment">-- If the file does not exist and it is opened for output, it should be</span><span>
</span><span id="line-119"></span><span class="hs-comment">-- created as a new file.  If @mode@ is 'WriteMode' and the file</span><span>
</span><span id="line-120"></span><span class="hs-comment">-- already exists, then it should be truncated to zero length.</span><span>
</span><span id="line-121"></span><span class="hs-comment">-- Some operating systems delete empty files, so there is no guarantee</span><span>
</span><span id="line-122"></span><span class="hs-comment">-- that the file will exist following an 'openFile' with @mode@</span><span>
</span><span id="line-123"></span><span class="hs-comment">-- 'WriteMode' unless it is subsequently written to successfully.</span><span>
</span><span id="line-124"></span><span class="hs-comment">-- The handle is positioned at the end of the file if @mode@ is</span><span>
</span><span id="line-125"></span><span class="hs-comment">-- 'AppendMode', and otherwise at the beginning (in which case its</span><span>
</span><span id="line-126"></span><span class="hs-comment">-- internal position is 0).</span><span>
</span><span id="line-127"></span><span class="hs-comment">-- The initial buffer mode is implementation-dependent.</span><span>
</span><span id="line-128"></span><span class="hs-comment">--</span><span>
</span><span id="line-129"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-130"></span><span class="hs-comment">--</span><span>
</span><span id="line-131"></span><span class="hs-comment">--  * 'System.IO.Error.isAlreadyInUseError' if the file is already open and</span><span>
</span><span id="line-132"></span><span class="hs-comment">--    cannot be reopened;</span><span>
</span><span id="line-133"></span><span class="hs-comment">--</span><span>
</span><span id="line-134"></span><span class="hs-comment">--  * 'System.IO.Error.isDoesNotExistError' if the file does not exist or</span><span>
</span><span id="line-135"></span><span class="hs-comment">--    (on POSIX systems) is a FIFO without a reader and 'WriteMode' was</span><span>
</span><span id="line-136"></span><span class="hs-comment">--    requested; or</span><span>
</span><span id="line-137"></span><span class="hs-comment">--</span><span>
</span><span id="line-138"></span><span class="hs-comment">--  * 'System.IO.Error.isPermissionError' if the user does not have permission</span><span>
</span><span id="line-139"></span><span class="hs-comment">--     to open the file.</span><span>
</span><span id="line-140"></span><span class="hs-comment">--</span><span>
</span><span id="line-141"></span><span class="hs-comment">-- Note: if you will be working with files containing binary data, you'll want to</span><span>
</span><span id="line-142"></span><span class="hs-comment">-- be using 'openBinaryFile'.</span><span>
</span><span id="line-143"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#openFile"><span class="hs-identifier hs-type">openFile</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-144"></span><span id="openFile"><span class="annot"><span class="annottext">openFile :: FilePath -&gt; IOMode -&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#openFile"><span class="hs-identifier hs-var hs-var">openFile</span></a></span></span><span> </span><span id="local-6989586621679554626"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554626"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span id="local-6989586621679554625"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554625"><span class="hs-identifier hs-var">im</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span>
</span><span id="line-145"></span><span>  </span><span class="annot"><span class="annottext">IO Handle -&gt; (IOException -&gt; IO Handle) -&gt; IO Handle
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchException"><span class="hs-identifier hs-var">catchException</span></a></span><span>
</span><span id="line-146"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; IOMode -&gt; Bool -&gt; Bool -&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#openFile%27"><span class="hs-identifier hs-var">openFile'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554626"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554625"><span class="hs-identifier hs-var">im</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.IO.Handle.FD.html#dEFAULT_OPEN_IN_BINARY_MODE"><span class="hs-identifier hs-var">dEFAULT_OPEN_IN_BINARY_MODE</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-147"></span><span>    </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679554621"><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679554621"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO Handle
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; IOException -&gt; IOException
</span><a href="GHC.IO.Handle.FD.html#addFilePathToIOError"><span class="hs-identifier hs-var">addFilePathToIOError</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;openFile&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554626"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679554621"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-148"></span><span>
</span><span id="line-149"></span><span class="hs-comment">-- | Like 'openFile', but opens the file in ordinary blocking mode.</span><span>
</span><span id="line-150"></span><span class="hs-comment">-- This can be useful for opening a FIFO for writing: if we open in</span><span>
</span><span id="line-151"></span><span class="hs-comment">-- non-blocking mode then the open will fail if there are no readers,</span><span>
</span><span id="line-152"></span><span class="hs-comment">-- whereas a blocking open will block until a reader appear.</span><span>
</span><span id="line-153"></span><span class="hs-comment">-- </span><span>
</span><span id="line-154"></span><span class="hs-comment">-- Note: when blocking happens, an OS thread becomes tied up with the</span><span>
</span><span id="line-155"></span><span class="hs-comment">-- processing, so the program must have at least another OS thread if</span><span>
</span><span id="line-156"></span><span class="hs-comment">-- it wants to unblock itself. By corollary, a non-threaded runtime</span><span>
</span><span id="line-157"></span><span class="hs-comment">-- will need a process-external trigger in order to become unblocked.</span><span>
</span><span id="line-158"></span><span class="hs-comment">--</span><span>
</span><span id="line-159"></span><span class="hs-comment">-- @since 4.4.0.0</span><span>
</span><span id="line-160"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#openFileBlocking"><span class="hs-identifier hs-type">openFileBlocking</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-161"></span><span id="openFileBlocking"><span class="annot"><span class="annottext">openFileBlocking :: FilePath -&gt; IOMode -&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#openFileBlocking"><span class="hs-identifier hs-var hs-var">openFileBlocking</span></a></span></span><span> </span><span id="local-6989586621679554619"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554619"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span id="local-6989586621679554618"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554618"><span class="hs-identifier hs-var">im</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-162"></span><span>  </span><span class="annot"><span class="annottext">IO Handle -&gt; (IOException -&gt; IO Handle) -&gt; IO Handle
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchException"><span class="hs-identifier hs-var">catchException</span></a></span><span>
</span><span id="line-163"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; IOMode -&gt; Bool -&gt; Bool -&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#openFile%27"><span class="hs-identifier hs-var">openFile'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554619"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554618"><span class="hs-identifier hs-var">im</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.IO.Handle.FD.html#dEFAULT_OPEN_IN_BINARY_MODE"><span class="hs-identifier hs-var">dEFAULT_OPEN_IN_BINARY_MODE</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-164"></span><span>    </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679554617"><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679554617"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO Handle
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; IOException -&gt; IOException
</span><a href="GHC.IO.Handle.FD.html#addFilePathToIOError"><span class="hs-identifier hs-var">addFilePathToIOError</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;openFile&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554619"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679554617"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-165"></span><span>
</span><span id="line-166"></span><span class="hs-comment">-- | Like 'openFile', but open the file in binary mode.</span><span>
</span><span id="line-167"></span><span class="hs-comment">-- On Windows, reading a file in text mode (which is the default)</span><span>
</span><span id="line-168"></span><span class="hs-comment">-- will translate CRLF to LF, and writing will translate LF to CRLF.</span><span>
</span><span id="line-169"></span><span class="hs-comment">-- This is usually what you want with text files.  With binary files</span><span>
</span><span id="line-170"></span><span class="hs-comment">-- this is undesirable; also, as usual under Microsoft operating systems,</span><span>
</span><span id="line-171"></span><span class="hs-comment">-- text mode treats control-Z as EOF.  Binary mode turns off all special</span><span>
</span><span id="line-172"></span><span class="hs-comment">-- treatment of end-of-line and end-of-file characters.</span><span>
</span><span id="line-173"></span><span class="hs-comment">-- (See also 'System.IO.hSetBinaryMode'.)</span><span>
</span><span id="line-174"></span><span>
</span><span id="line-175"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#openBinaryFile"><span class="hs-identifier hs-type">openBinaryFile</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-176"></span><span id="openBinaryFile"><span class="annot"><span class="annottext">openBinaryFile :: FilePath -&gt; IOMode -&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#openBinaryFile"><span class="hs-identifier hs-var hs-var">openBinaryFile</span></a></span></span><span> </span><span id="local-6989586621679554616"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554616"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span id="local-6989586621679554615"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554615"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-177"></span><span>  </span><span class="annot"><span class="annottext">IO Handle -&gt; (IOException -&gt; IO Handle) -&gt; IO Handle
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchException"><span class="hs-identifier hs-var">catchException</span></a></span><span>
</span><span id="line-178"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; IOMode -&gt; Bool -&gt; Bool -&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#openFile%27"><span class="hs-identifier hs-var">openFile'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554616"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554615"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-179"></span><span>    </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679554614"><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679554614"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO Handle
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; IOException -&gt; IOException
</span><a href="GHC.IO.Handle.FD.html#addFilePathToIOError"><span class="hs-identifier hs-var">addFilePathToIOError</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;openBinaryFile&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554616"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679554614"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-180"></span><span>
</span><span id="line-181"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#openFile%27"><span class="hs-identifier hs-type">openFile'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-182"></span><span id="openFile%27"><span class="annot"><span class="annottext">openFile' :: FilePath -&gt; IOMode -&gt; Bool -&gt; Bool -&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#openFile%27"><span class="hs-identifier hs-var hs-var">openFile'</span></a></span></span><span> </span><span id="local-6989586621679554613"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554613"><span class="hs-identifier hs-var">filepath</span></a></span></span><span> </span><span id="local-6989586621679554612"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554612"><span class="hs-identifier hs-var">iomode</span></a></span></span><span> </span><span id="local-6989586621679554611"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554611"><span class="hs-identifier hs-var">binary</span></a></span></span><span> </span><span id="local-6989586621679554610"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554610"><span class="hs-identifier hs-var">non_blocking</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-183"></span><span>  </span><span class="hs-comment">-- first open the file to get an FD</span><span>
</span><span id="line-184"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679554609"><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554609"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679554608"><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554608"><span class="hs-identifier hs-var">fd_type</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; IOMode -&gt; Bool -&gt; IO (FD, IODeviceType)
</span><a href="GHC.IO.FD.html#openFile"><span class="hs-identifier hs-var">FD.openFile</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554613"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554612"><span class="hs-identifier hs-var">iomode</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554610"><span class="hs-identifier hs-var">non_blocking</span></a></span><span>
</span><span id="line-185"></span><span>
</span><span id="line-186"></span><span>  </span><span id="local-6989586621679554606"><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679554606"><span class="hs-identifier hs-var">mb_codec</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554611"><span class="hs-identifier hs-var">binary</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding -&gt; IO (Maybe TextEncoding)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">(TextEncoding -&gt; Maybe TextEncoding)
-&gt; IO TextEncoding -&gt; IO (Maybe TextEncoding)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; Maybe TextEncoding
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getLocaleEncoding"><span class="hs-identifier hs-var">getLocaleEncoding</span></a></span><span>
</span><span id="line-187"></span><span>
</span><span id="line-188"></span><span>  </span><span class="hs-comment">-- then use it to make a Handle</span><span>
</span><span id="line-189"></span><span>  </span><span class="annot"><span class="annottext">FD
-&gt; IODeviceType
-&gt; FilePath
-&gt; IOMode
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#mkHandleFromFD"><span class="hs-identifier hs-var">mkHandleFromFD</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554609"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554608"><span class="hs-identifier hs-var">fd_type</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554613"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554612"><span class="hs-identifier hs-var">iomode</span></a></span><span>
</span><span id="line-190"></span><span>                   </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span> </span><span class="hs-comment">{- do not *set* non-blocking mode -}</span><span>
</span><span id="line-191"></span><span>                   </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679554606"><span class="hs-identifier hs-var">mb_codec</span></a></span><span>
</span><span id="line-192"></span><span>            </span><span class="annot"><span class="annottext">IO Handle -&gt; IO () -&gt; IO Handle
forall a b. IO a -&gt; IO b -&gt; IO a
</span><a href="GHC.IO.html#onException"><span class="hs-operator hs-var">`onException`</span></a></span><span> </span><span class="annot"><span class="annottext">FD -&gt; IO ()
forall a. IODevice a =&gt; a -&gt; IO ()
</span><a href="GHC.IO.Device.html#close"><span class="hs-identifier hs-var">IODevice.close</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554609"><span class="hs-identifier hs-var">fd</span></a></span><span>
</span><span id="line-193"></span><span>        </span><span class="hs-comment">-- NB. don't forget to close the FD if mkHandleFromFD fails, otherwise</span><span>
</span><span id="line-194"></span><span>        </span><span class="hs-comment">-- this FD leaks.</span><span>
</span><span id="line-195"></span><span>        </span><span class="hs-comment">-- ASSERT: if we just created the file, then fdToHandle' won't fail</span><span>
</span><span id="line-196"></span><span>        </span><span class="hs-comment">-- (so we don't need to worry about removing the newly created file</span><span>
</span><span id="line-197"></span><span>        </span><span class="hs-comment">--  in the event of an error).</span><span>
</span><span id="line-198"></span><span>
</span><span id="line-199"></span><span>
</span><span id="line-200"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-201"></span><span class="hs-comment">-- Converting file descriptors from/to Handles</span><span>
</span><span id="line-202"></span><span>
</span><span id="line-203"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#mkHandleFromFD"><span class="hs-identifier hs-type">mkHandleFromFD</span></a></span><span>
</span><span id="line-204"></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.FD.html#FD"><span class="hs-identifier hs-type">FD.FD</span></a></span><span>
</span><span id="line-205"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#IODeviceType"><span class="hs-identifier hs-type">IODeviceType</span></a></span><span>
</span><span id="line-206"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>  </span><span class="hs-comment">-- a string describing this file descriptor (e.g. the filename)</span><span>
</span><span id="line-207"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span>
</span><span id="line-208"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>      </span><span class="hs-comment">--  *set* non-blocking mode on the FD</span><span>
</span><span id="line-209"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier hs-type">TextEncoding</span></a></span><span>
</span><span id="line-210"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-211"></span><span>
</span><span id="line-212"></span><span id="mkHandleFromFD"><span class="annot"><span class="annottext">mkHandleFromFD :: FD
-&gt; IODeviceType
-&gt; FilePath
-&gt; IOMode
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#mkHandleFromFD"><span class="hs-identifier hs-var hs-var">mkHandleFromFD</span></a></span></span><span> </span><span id="local-6989586621679554603"><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554603"><span class="hs-identifier hs-var">fd0</span></a></span></span><span> </span><span id="local-6989586621679554602"><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554602"><span class="hs-identifier hs-var">fd_type</span></a></span></span><span> </span><span id="local-6989586621679554601"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554601"><span class="hs-identifier hs-var">filepath</span></a></span></span><span> </span><span id="local-6989586621679554600"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554600"><span class="hs-identifier hs-var">iomode</span></a></span></span><span> </span><span id="local-6989586621679554599"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554599"><span class="hs-identifier hs-var">set_non_blocking</span></a></span></span><span> </span><span id="local-6989586621679554598"><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679554598"><span class="hs-identifier hs-var">mb_codec</span></a></span></span><span>
</span><span id="line-213"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span>    </span><span class="hs-comment">-- turn on non-blocking mode</span><span>
</span><span id="line-216"></span><span>    </span><span class="hs-identifier">fd</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">set_non_blocking</span><span> </span><span>
</span><span id="line-217"></span><span>             </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">FD.setNonBlockingMode</span><span> </span><span class="hs-identifier">fd0</span><span> </span><span class="hs-identifier">True</span><span>
</span><span id="line-218"></span><span>             </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">fd0</span><span class="hs-cpp">
#else
</span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554599"><span class="hs-identifier hs-var">set_non_blocking</span></a></span><span> </span><span class="hs-comment">-- warning suppression</span><span>
</span><span id="line-221"></span><span>    </span><span id="local-6989586621679554597"><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554597"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FD -&gt; IO FD
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554603"><span class="hs-identifier hs-var">fd0</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-224"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679554596"><span class="annot"><span class="annottext">nl :: NewlineMode
</span><a href="#local-6989586621679554596"><span class="hs-identifier hs-var hs-var">nl</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679554598"><span class="hs-identifier hs-var">mb_codec</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="GHC.IO.Handle.Types.html#nativeNewlineMode"><span class="hs-identifier hs-var">nativeNewlineMode</span></a></span><span>
</span><span id="line-225"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="GHC.IO.Handle.Types.html#noNewlineTranslation"><span class="hs-identifier hs-var">noNewlineTranslation</span></a></span><span>
</span><span id="line-226"></span><span>
</span><span id="line-227"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554602"><span class="hs-identifier hs-var">fd_type</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-228"></span><span>        </span><span class="annot"><span class="annottext">IODeviceType
</span><a href="GHC.IO.Device.html#Directory"><span class="hs-identifier hs-var">Directory</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span>
</span><span id="line-229"></span><span>           </span><span class="annot"><span class="annottext">IOException -&gt; IO Handle
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#InappropriateType"><span class="hs-identifier hs-var">InappropriateType</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;openFile&quot;</span></span><span>
</span><span id="line-230"></span><span>                           </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;is a directory&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-231"></span><span>
</span><span id="line-232"></span><span>        </span><span class="annot"><span class="annottext">IODeviceType
</span><a href="GHC.IO.Device.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span><span>
</span><span id="line-233"></span><span>           </span><span class="hs-comment">-- only *Streams* can be DuplexHandles.  Other read/write</span><span>
</span><span id="line-234"></span><span>           </span><span class="hs-comment">-- Handles must share a buffer.</span><span>
</span><span id="line-235"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#ReadWriteMode"><span class="hs-identifier hs-var">ReadWriteMode</span></a></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554600"><span class="hs-identifier hs-var">iomode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span>
</span><span id="line-236"></span><span>                </span><span class="annot"><span class="annottext">FD -&gt; FilePath -&gt; Maybe TextEncoding -&gt; NewlineMode -&gt; IO Handle
forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev -&gt; FilePath -&gt; Maybe TextEncoding -&gt; NewlineMode -&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkDuplexHandle"><span class="hs-identifier hs-var">mkDuplexHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554597"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554601"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679554598"><span class="hs-identifier hs-var">mb_codec</span></a></span><span> </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679554596"><span class="hs-identifier hs-var">nl</span></a></span><span>
</span><span id="line-237"></span><span>                   </span><span>
</span><span id="line-238"></span><span>
</span><span id="line-239"></span><span>        </span><span id="local-6989586621679554586"><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554586"><span class="hs-identifier hs-var">_other</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span>
</span><span id="line-240"></span><span>           </span><span class="annot"><span class="annottext">FD
-&gt; FilePath
-&gt; IOMode
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; IO Handle
forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; FilePath
-&gt; IOMode
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkFileHandle"><span class="hs-identifier hs-var">mkFileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554597"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554601"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554600"><span class="hs-identifier hs-var">iomode</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679554598"><span class="hs-identifier hs-var">mb_codec</span></a></span><span> </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679554596"><span class="hs-identifier hs-var">nl</span></a></span><span>
</span><span id="line-241"></span><span>
</span><span id="line-242"></span><span class="hs-comment">-- | Old API kept to avoid breaking clients</span><span>
</span><span id="line-243"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#fdToHandle%27"><span class="hs-identifier hs-type">fdToHandle'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>
</span><span id="line-244"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Device.html#IODeviceType"><span class="hs-identifier hs-type">IODeviceType</span></a></span><span>
</span><span id="line-245"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-comment">-- is_socket on Win, non-blocking on Unix</span><span>
</span><span id="line-246"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-247"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span>
</span><span id="line-248"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-comment">-- binary</span><span>
</span><span id="line-249"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-250"></span><span id="fdToHandle%27"><span class="annot"><span class="annottext">fdToHandle' :: CInt
-&gt; Maybe IODeviceType
-&gt; Bool
-&gt; FilePath
-&gt; IOMode
-&gt; Bool
-&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#fdToHandle%27"><span class="hs-identifier hs-var hs-var">fdToHandle'</span></a></span></span><span> </span><span id="local-6989586621679554584"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679554584"><span class="hs-identifier hs-var">fdint</span></a></span></span><span> </span><span id="local-6989586621679554583"><span class="annot"><span class="annottext">Maybe IODeviceType
</span><a href="#local-6989586621679554583"><span class="hs-identifier hs-var">mb_type</span></a></span></span><span> </span><span id="local-6989586621679554582"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554582"><span class="hs-identifier hs-var">is_socket</span></a></span></span><span> </span><span id="local-6989586621679554581"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554581"><span class="hs-identifier hs-var">filepath</span></a></span></span><span> </span><span id="local-6989586621679554580"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554580"><span class="hs-identifier hs-var">iomode</span></a></span></span><span> </span><span id="local-6989586621679554579"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554579"><span class="hs-identifier hs-var">binary</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-251"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679554574"><span class="annot"><span class="annottext">mb_stat :: Maybe (IODeviceType, CDev, CIno)
</span><a href="#local-6989586621679554574"><span class="hs-identifier hs-var hs-var">mb_stat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe IODeviceType
</span><a href="#local-6989586621679554583"><span class="hs-identifier hs-var">mb_type</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-252"></span><span>                        </span><span class="annot"><span class="annottext">Maybe IODeviceType
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe (IODeviceType, CDev, CIno)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-253"></span><span>                          </span><span class="hs-comment">-- mkFD will do the stat:</span><span>
</span><span id="line-254"></span><span>                        </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">IODeviceType
</span><a href="GHC.IO.Device.html#RegularFile"><span class="hs-identifier hs-var">RegularFile</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe (IODeviceType, CDev, CIno)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-255"></span><span>                          </span><span class="hs-comment">-- no stat required for streams etc.:</span><span>
</span><span id="line-256"></span><span>                        </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679554572"><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554572"><span class="hs-identifier hs-var">other</span></a></span></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(IODeviceType, CDev, CIno) -&gt; Maybe (IODeviceType, CDev, CIno)
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554572"><span class="hs-identifier hs-var">other</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">CDev
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">CIno
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-257"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679554571"><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554571"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679554570"><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554570"><span class="hs-identifier hs-var">fd_type</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CInt
-&gt; IOMode
-&gt; Maybe (IODeviceType, CDev, CIno)
-&gt; Bool
-&gt; Bool
-&gt; IO (FD, IODeviceType)
</span><a href="GHC.IO.FD.html#mkFD"><span class="hs-identifier hs-var">FD.mkFD</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679554584"><span class="hs-identifier hs-var">fdint</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554580"><span class="hs-identifier hs-var">iomode</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (IODeviceType, CDev, CIno)
</span><a href="#local-6989586621679554574"><span class="hs-identifier hs-var">mb_stat</span></a></span><span>
</span><span id="line-258"></span><span>                       </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554582"><span class="hs-identifier hs-var">is_socket</span></a></span><span>
</span><span id="line-259"></span><span>                       </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554582"><span class="hs-identifier hs-var">is_socket</span></a></span><span>
</span><span id="line-260"></span><span>  </span><span id="local-6989586621679554568"><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679554568"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554579"><span class="hs-identifier hs-var">binary</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding -&gt; IO (Maybe TextEncoding)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">(TextEncoding -&gt; Maybe TextEncoding)
-&gt; IO TextEncoding -&gt; IO (Maybe TextEncoding)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; Maybe TextEncoding
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getLocaleEncoding"><span class="hs-identifier hs-var">getLocaleEncoding</span></a></span><span>
</span><span id="line-261"></span><span>  </span><span class="annot"><span class="annottext">FD
-&gt; IODeviceType
-&gt; FilePath
-&gt; IOMode
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#mkHandleFromFD"><span class="hs-identifier hs-var">mkHandleFromFD</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554571"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554570"><span class="hs-identifier hs-var">fd_type</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554581"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554580"><span class="hs-identifier hs-var">iomode</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679554582"><span class="hs-identifier hs-var">is_socket</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679554568"><span class="hs-identifier hs-var">enc</span></a></span><span>
</span><span id="line-262"></span><span>
</span><span id="line-263"></span><span>
</span><span id="line-264"></span><span class="hs-comment">-- | Turn an existing file descriptor into a Handle.  This is used by</span><span>
</span><span id="line-265"></span><span class="hs-comment">-- various external libraries to make Handles.</span><span>
</span><span id="line-266"></span><span class="hs-comment">--</span><span>
</span><span id="line-267"></span><span class="hs-comment">-- Makes a binary Handle.  This is for historical reasons; it should</span><span>
</span><span id="line-268"></span><span class="hs-comment">-- probably be a text Handle with the default encoding and newline</span><span>
</span><span id="line-269"></span><span class="hs-comment">-- translation instead.</span><span>
</span><span id="line-270"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#fdToHandle"><span class="hs-identifier hs-type">fdToHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="System.Posix.Internals.html#FD"><span class="hs-identifier hs-type">Posix.FD</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-271"></span><span id="fdToHandle"><span class="annot"><span class="annottext">fdToHandle :: CInt -&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#fdToHandle"><span class="hs-identifier hs-var hs-var">fdToHandle</span></a></span></span><span> </span><span id="local-6989586621679554566"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679554566"><span class="hs-identifier hs-var">fdint</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-272"></span><span>   </span><span id="local-6989586621679554565"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554565"><span class="hs-identifier hs-var">iomode</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CInt -&gt; IO IOMode
</span><a href="System.Posix.Internals.html#fdGetMode"><span class="hs-identifier hs-var">Posix.fdGetMode</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679554566"><span class="hs-identifier hs-var">fdint</span></a></span><span>
</span><span id="line-273"></span><span>   </span><span class="hs-special">(</span><span id="local-6989586621679554563"><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554563"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679554562"><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554562"><span class="hs-identifier hs-var">fd_type</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CInt
-&gt; IOMode
-&gt; Maybe (IODeviceType, CDev, CIno)
-&gt; Bool
-&gt; Bool
-&gt; IO (FD, IODeviceType)
</span><a href="GHC.IO.FD.html#mkFD"><span class="hs-identifier hs-var">FD.mkFD</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679554566"><span class="hs-identifier hs-var">fdint</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554565"><span class="hs-identifier hs-var">iomode</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (IODeviceType, CDev, CIno)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-274"></span><span>            </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-comment">{-is_socket-}</span><span> </span><span>
</span><span id="line-275"></span><span>              </span><span class="hs-comment">-- NB. the is_socket flag is False, meaning that:</span><span>
</span><span id="line-276"></span><span>              </span><span class="hs-comment">--  on Windows we're guessing this is not a socket (XXX)</span><span>
</span><span id="line-277"></span><span>            </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-comment">{-is_nonblock-}</span><span>
</span><span id="line-278"></span><span>              </span><span class="hs-comment">-- file descriptors that we get from external sources are</span><span>
</span><span id="line-279"></span><span>              </span><span class="hs-comment">-- not put into non-blocking mode, because that would affect</span><span>
</span><span id="line-280"></span><span>              </span><span class="hs-comment">-- other users of the file descriptor</span><span>
</span><span id="line-281"></span><span>   </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679554559"><span class="annot"><span class="annottext">fd_str :: FilePath
</span><a href="#local-6989586621679554559"><span class="hs-identifier hs-var hs-var">fd_str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&lt;file descriptor: &quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">FD -&gt; FilePath
forall a. Show a =&gt; a -&gt; FilePath
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554563"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&gt;&quot;</span></span><span>
</span><span id="line-282"></span><span>   </span><span class="annot"><span class="annottext">FD
-&gt; IODeviceType
-&gt; FilePath
-&gt; IOMode
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#mkHandleFromFD"><span class="hs-identifier hs-var">mkHandleFromFD</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554563"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679554562"><span class="hs-identifier hs-var">fd_type</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554559"><span class="hs-identifier hs-var">fd_str</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679554565"><span class="hs-identifier hs-var">iomode</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-comment">{-non-block-}</span><span> </span><span>
</span><span id="line-283"></span><span>                  </span><span class="annot"><span class="annottext">Maybe TextEncoding
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-comment">-- bin mode</span><span>
</span><span id="line-284"></span><span>
</span><span id="line-285"></span><span class="hs-comment">-- | Turn an existing Handle into a file descriptor. This function throws an</span><span>
</span><span id="line-286"></span><span class="hs-comment">-- IOError if the Handle does not reference a file descriptor.</span><span>
</span><span id="line-287"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#handleToFd"><span class="hs-identifier hs-type">handleToFd</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.FD.html#FD"><span class="hs-identifier hs-type">FD.FD</span></a></span><span>
</span><span id="line-288"></span><span id="handleToFd"><span class="annot"><span class="annottext">handleToFd :: Handle -&gt; IO FD
</span><a href="GHC.IO.Handle.FD.html#handleToFd"><span class="hs-identifier hs-var hs-var">handleToFd</span></a></span></span><span> </span><span id="local-6989586621679554557"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679554557"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679554557"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-289"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679554555"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679554555"><span class="hs-identifier hs-var">mv</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-290"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span class="annot"><span class="annottext">haDevice :: ()
</span><a href="GHC.IO.Handle.Types.html#haDevice"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621679554545"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679554545"><span class="hs-identifier hs-var">dev</span></a></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; IO Handle__
forall a. MVar a -&gt; IO a
</span><a href="GHC.MVar.html#readMVar"><span class="hs-identifier hs-var">readMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679554555"><span class="hs-identifier hs-var">mv</span></a></span><span>
</span><span id="line-291"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Maybe FD
forall a b. (Typeable a, Typeable b) =&gt; a -&gt; Maybe b
</span><a href="Data.Typeable.html#cast"><span class="hs-identifier hs-var">cast</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679554545"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-292"></span><span>      </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679554542"><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554542"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FD -&gt; IO FD
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679554542"><span class="hs-identifier hs-var">fd</span></a></span><span>
</span><span id="line-293"></span><span>      </span><span class="annot"><span class="annottext">Maybe FD
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; IO FD
forall {a}. FilePath -&gt; IO a
</span><a href="#local-6989586621679554541"><span class="hs-identifier hs-var">throwErr</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;not a file descriptor&quot;</span></span><span>
</span><span id="line-294"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Types.html#DuplexHandle"><span class="hs-identifier hs-type">DuplexHandle</span></a></span><span class="hs-special">{</span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; IO FD
forall {a}. FilePath -&gt; IO a
</span><a href="#local-6989586621679554541"><span class="hs-identifier hs-var">throwErr</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;not a file handle&quot;</span></span><span>
</span><span id="line-295"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-296"></span><span>    </span><span id="local-6989586621679554541"><span class="annot"><span class="annottext">throwErr :: FilePath -&gt; IO a
</span><a href="#local-6989586621679554541"><span class="hs-identifier hs-var hs-var">throwErr</span></a></span></span><span> </span><span id="local-6989586621679554539"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554539"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span> </span><span class="annot"><span class="annottext">(IOException -&gt; IO a) -&gt; IOException -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle -&gt; Maybe Handle
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679554557"><span class="hs-identifier hs-var">h</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-297"></span><span>      </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#InappropriateType"><span class="hs-identifier hs-var">InappropriateType</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;handleToFd&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679554539"><span class="hs-identifier hs-var">msg</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-298"></span><span>
</span><span id="line-299"></span><span>
</span><span id="line-300"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-301"></span><span class="hs-comment">-- Are files opened by default in text or binary mode, if the user doesn't</span><span>
</span><span id="line-302"></span><span class="hs-comment">-- specify?</span><span>
</span><span id="line-303"></span><span>
</span><span id="line-304"></span><span class="annot"><a href="GHC.IO.Handle.FD.html#dEFAULT_OPEN_IN_BINARY_MODE"><span class="hs-identifier hs-type">dEFAULT_OPEN_IN_BINARY_MODE</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-305"></span><span id="dEFAULT_OPEN_IN_BINARY_MODE"><span class="annot"><span class="annottext">dEFAULT_OPEN_IN_BINARY_MODE :: Bool
</span><a href="GHC.IO.Handle.FD.html#dEFAULT_OPEN_IN_BINARY_MODE"><span class="hs-identifier hs-var hs-var">dEFAULT_OPEN_IN_BINARY_MODE</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-306"></span></pre></body></html>